package com.jpa.demo.factorybeanexample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class FactoryBeanController {

    @Autowired
    private ApplicationContext context;

    @GetMapping("/beans")
    public void testBeans() {
        // 直接获取 Bean，获取到的其实是通过getObject产生的bean
        Object factoryBean = context.getBean("userServiceFactoryBean");
        System.out.println("Bean named 'userServiceFactoryBean': " + factoryBean.getClass().getName());

        // 通过 & 获取 FactoryBean 本身
        Object actualFactoryBean = context.getBean("&userServiceFactoryBean");
        System.out.println("FactoryBean itself: " + actualFactoryBean.getClass().getName());
    }
}


